---
# Configuration for the Fedora Notifications webapp
- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - python-fmn
  - python-psycopg2
  - libsemanage-python
  - python-memcached
  - python-flask-openid
  - python-bunch
  notify:
  - restart apache
  when:
    inventory_hostname.startswith('notifs-web02.iad2')
  tags:
  - notifs
  - notifs/frontend

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - python3-fmn
  - python3-psycopg2
  - python3-libsemanage
  - python3-memcached
  - python3-flask-openid
  notify:
  - restart apache
  when:
    inventory_hostname.startswith('notifs-web01') or env == 'staging'
  tags:
  - notifs
  - notifs/frontend

#- name: Install epel-testing fmn on stage
#  package: name={{ item }} state=present enablerepo=epel-testing
#  with_items:
#  - python-fmn
#  when: env == "staging"
#  notify:
#  - restart apache
#  tags:
#  - notifs
#  - notifs/frontend

- name: copy fmn app configuration
  template: >
    src={{ item }} dest=/etc/fedmsg.d/{{ item }}
    owner=apache group=apache mode=0600
  with_items:
  - fmn.web.py
  notify:
  - restart apache
  tags:
  - notifs
  - notifs/frontend

- name: destroy a bogus config file brought in by python-datanommer-models
  file: dest=/etc/fedmsg.d/datanommer.py state=absent
  notify:
  - restart apache
  tags:
  - notifs
  - notifs/frontend

- name: setup symlink to fedora theme
  file: >
    src=/usr/share/fmn/static/bootstrap-3.3.4-fedora
    dest=/usr/share/fmn/static/bootstrap
    state=link
  tags:
  - notifs
  - notifs/frontend

- name: copy fmn httpd config
  template: >
    src=fmn.web.conf dest=/etc/httpd/conf.d/fmn.web.conf
    owner=apache group=apache mode=0644
  notify:
  - restart apache
  tags:
  - notifs
  - notifs/frontend

- name: copy custom wsgi file
  copy: src=fmn.web.wsgi dest=/usr/share/fmn/fmn.web.wsgi mode=0644
  notify:
  - restart apache
  tags:
  - notifs
  - notifs/frontend

- name: copy app configuration
  template: >
    src=fmn.web.cfg dest=/etc/fmn.web.cfg
    owner=root group=apache mode=0640
  notify:
  - restart apache
  tags:
  - notifs
  - notifs/frontend

#- name: create live docs directory
#  file: >
#    dest=/usr/lib/python2.6/site-packages/fmn/web/docs/
#    state=directory
#  tags:
#  - notifs
#  - notifs/frontend

#- name: copy live docs
#  copy: src={{ item }} dest=/usr/lib/python2.6/site-packages/fmn/web/docs
#  with_fileglob: fedora-sitedocs/*.rst
#  tags:
#  - notifs
#  - notifs/frontend

#- name: apply selinux type to static files
#  file: >
#    dest=/usr/share/fmn/static
#    setype=httpd_sys_content_t
#    state=directory
#    recurse=yes
#  tags:
#  - notifs
#  - notifs/frontend
#  - selinux

- name: ensure selinux lets httpd talk to postgres, memcached, and mail
  seboolean: name={{item}} state=yes persistent=yes
  with_items:
  - httpd_can_network_connect_db
  - httpd_can_network_memcache
  - httpd_can_sendmail
  tags:
  - notifs
  - notifs/frontend
  - selinux

- name: Install SAR script
  copy:
    src: fmn-sar.py
    dest: /usr/local/bin/fmn-sar.py
    mode: 0755
    owner: apache
    group: apache
  when: inventory_hostname.startswith('notifs-web01')
  tags:
  - notifs
  - SAR
  - GDPR
